{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.4 Newton–Raphson"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Square root of 25.0 is about 5.000012953048684\n"
     ]
    }
   ],
   "source": [
    "# Newton–Raphson for square root\n",
    "# Find x such that x ** 2 -  24 is whitin espilon of 0\n",
    "k = 24.0\n",
    "espilon = 0.01\n",
    "guess = k / 2\n",
    "while abs(guess ** 2 - k) >= espilon:\n",
    "    guess = guess - ((guess ** 2) - k) / (2 * guess)\n",
    "print('Square root of', k, 'is about', guess)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
